package com.dhcc.wb.operationlog;

import com.dhcc.bussiness.page.PageBean;
import org.apache.log4j.Logger;
import java.util.List;

/**
 * 操作日志Service
 * @author wanggx
 * @date 2019/12/5 17:06
 */
public class OperationLogService {
    private static Logger logger = Logger.getLogger(OperationLogService.class);
    public PageBean<OperationLogModel> findSh_logServiceByPage(int currentPage, int currentCount, String name, String typeName) {
        OperationLogDao dao = new OperationLogDao();
        PageBean<OperationLogModel> pageBean = new PageBean<OperationLogModel>();
        try {
            pageBean.setCurrentPage(currentPage);
            pageBean.setCurrentCount(currentCount);
            Integer totalCount = dao.queryCount(name,typeName);
            logger.info(totalCount + "====totalCount这是总数");
            pageBean.setTotalCount(totalCount);
            int totalPage = (int) Math.ceil(1.0*totalCount/currentCount);
            pageBean.setTotalPage(totalPage);
            String pageStr[] = new String[0];
            if(totalPage == 0){
                pageStr = new String[1];
                pageStr[0] = "第1页";
            } else {
                pageStr = new String[totalPage];
            }

            for (int i=0; i<totalPage; i++){
                pageStr[i]= "第"+(i+1)+"页";
            }
            pageBean.setPageTotalPageList(pageStr);
            int startIndex = (currentPage-1)*currentCount;
            List<OperationLogModel> pageList = dao.findSh_logServiceByPage(startIndex,currentCount,name,typeName);
            pageBean.setPageList(pageList);
        }catch (Exception e) {
            e.printStackTrace();
        }
        return pageBean;
    }

}
